<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
    $(function(){
        $("#textColumnName").bind("blur",checkColumnName);

        loadColumnName();
        $("#btnSubmitNewAdmin").bind("click",submitAdmin);
    });
    function submitAdmin(){
        if(checkColumnName()==false)
            return;

        var id = $("#hdidcolumn").val();
        var columnName = $("#textColumnName").val();
        var params = {
            id:id,
            columnName:columnName
        };

        $.ajax({
            type:"post",
            url:"admin.php/article/addColumn",
            dataType:"json",
            data:params,
            success:function(data){
                parent.loadColumn();
                alert("提交成功");
                $("#btnCloseColumnName").trigger("click");
            }
        });
    }

    function loadColumnName(){
        var id = $("#hdidcolumn").val();
        if(id==0)
            return;

        var params = {id:id};
        $.ajax({
            type:"post",
            url:"admin.php/article/getColumnById",
            dataType:"json",
            data:params,
            success:function(data){
                $("#textColumnName").val(data.name);
            }
        });
    }
    function checkColumnName(){

        var columnname = $("#textColumnName").val();
        if(IsEmpty(columnname)){
            SetError("textColumnName","分类名称不能为空");
            return false;
        }
        var len = columnname.length;
        if(len>30){
            SetError("textColumnName","最多30字符");
            return false;
        }
        var id = $("#hdidcolumn").val();
        var params = {
            id:id,
            columnName:columnname
        };
        var isok=true;
        $.ajax({
            type:"post",
            url:"admin.php/article/checkColumn",
            dataType:"json",
            data:params,
            async:false,
            success:function(data){
                if(data.ReturnCode!="1"){
                    isok=false;
                    SetError("textColumnName","该分类已存在");
                }
            }
        });
        if(isok==false)
            return false;

        SetOK("textColumnName");
        return true;
    }

</script>
<div class="pageContent">
    <form class="pageForm required-validate">
        <div class="pageFormContent" style="width: 98%;" layoutH="56">
            <table class="tableNewUser">
                <tr>
                    <td>分类名称：</td>
                    <td><input id="textColumnName" type="text" value="" /></td>
                </tr>
                <tr>
                    <td colspan="2" style='line-height: 40px'>&nbsp;&nbsp;</td>
                </tr>
            </table>
            <input type="hidden" id="hdidcolumn"
                   value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

            <div class="buttonActive" style="width: 120px; margin-left: 50px;">
                <div class="buttonContent">
                    <button id="btnSubmitNewAdmin" type="button" style="width: 80px">提
                        交</button>
                </div>
            </div>

            <div class="button" style="text-align: right">
                <div class="buttonContent" style="text-align: right">
                    <button id="btnCloseColumnName" type="button" class="close"
                            style="width: 80px">取 消</button>
                </div>
            </div>
        </div>
    </form>
</div>
